







#include "config.h"
#include <stdio.h>
#include <string.h>



static tTemconfig g_ItemConfigs[ItemConfig_number];
static int g_ItemConfig_count = 0;




//解析配置文件
int ParseConfig(void )
{
	FILE *filep;
	char buff[100];
	char * p = buff;


	//打开文件
	
	filep =  fopen(CONFIG_PATH,"r"); 
	if(!filep)
	{
		printf("connot open  %s ", CONFIG_PATH);
		return -1;

	}

	
	//处理文件
	while(fgets(buff, 100, filep))
	{
		buff[99] = '\0';

		p = buff;
		while(*p == ' ' || *p == '\t')
		{
			p++;
		}

		if(*p == '#')
		{
			continue;
		}



		g_ItemConfigs[g_ItemConfig_count].commend[0] = '\0';
		
		g_ItemConfigs[g_ItemConfig_count].index = g_ItemConfig_count;
		sscanf(p, "%s %d %s", g_ItemConfigs[g_ItemConfig_count].name, &g_ItemConfigs[g_ItemConfig_count].bcanbetouched, \
								g_ItemConfigs[g_ItemConfig_count].commend);



		g_ItemConfig_count++;
	}

	return 0;

}





int GetItemConfigCount(void)
{

	return g_ItemConfig_count;


}
PTemconfig GetItemConfigByIndex(int index)
{

	if(index < g_ItemConfig_count)
		return &g_ItemConfigs[index];
	else
		return NULL;




	



}
PTemconfig GetItemConfigByName(char *name)
{
	int i;
	for(i=0 ;i<g_ItemConfig_count ;i++)
	{
		if(strcmp(g_ItemConfigs[i].name, name)==0)
		{
			return &g_ItemConfigs[i];
		}
	}


	return NULL;


}























